﻿<!DOCTYPE>

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>装试班次关联到班</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style>
        .easyui-linkbutton{margin-left:20px;} 
        table tr td{padding:0px 5px}
        .Btitle{background-color: #ddd; padding: 10px; margin: 5px 10px;}
    </style>
</head>
<body>
    <div class="panelSection">    
        <div class="easyui-panel " title="查询区域" style="padding:3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="searchForm" method="post">
	    	<table>
	    		<tr class="divLabel">
                    <td>分厂:</td>
                    <td>工区:</td>
	    		</tr>
	    		<tr>
	    			<td><input id="selFactory" name="Factory" style="width: 120px; height: 22px" data-options='editable:false'/></td>
	    			<td><input id="selWorkCenter" name="WorkCenter" class="easyui-combobox" style="width: 120px; height: 22px" data-options='editable:false'/></td>
                    <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchData()">查询</a></td>
	    			<td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="page.searchReset()">重置</a></td>
	    		</tr>
	    	</table>
	    </form>
        </div> 
    </div>

    <div class="panelSection">    
        <div class="easyui-panel " title="查询结果" style="padding:3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
        <table id="OrderTabel" style="height:240px;width: 100%" data-options="rownumbers:true"></table>
        </div>
      </div>
    <div class="panelSection" >
        <div class="easyui-panel " title="基本信息" style="padding:3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="EditerForm" method="post">
	    	<table>
	    		<tr class="divLabel">
                    <td>班次:</td>
                    <td>班:</td>
	    		</tr>
	    		<tr>
	    			<td><input id="selWorkshift" name="WORKSHIFTID" style="width: 120px; height: 22px" class="easyui-combobox" data-options='editable:false'/></td>
	    			<td><input id="selShift" name="SHIFTID" style="width: 120px; height: 22px" class="easyui-combobox" data-options='editable:false'/></td>
	    		</tr>
	    	</table>
	    </form>
        </div>
	  </div>
    <div class="panelSection">    
        <div class="easyui-panel " title="按钮区域" style="padding:3px;width: 100%" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
             <a href="javascript:void(0)" onclick="page.CreateShiftWorkshiftMap()" class="easyui-linkbutton" data-options="width:120" style="margin: 10px 0 10px 20px;">新建</a>
             <a href="javascript:void(0)" onclick="page.SaveShiftWorkshiftMap()" class="easyui-linkbutton" data-options="width:120"  style="margin: 10px 0 10px 20px;">保存</a>
        </div>
    </div>
     <!--信息提示区域-->
     <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript" >
    //创建人：longb
    //日期：2022-07-19
    //描述：装试班次维护
    var page = {
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ApsZsTeamShiftHandler.ashx",
        init: function () {
            page.initPageData();
            page.bind();
        },
        initPageData: function () {
            page.post({ action: "InitPageData" }, true, function (res) {
                //绑定班次下拉框
                $("#selWorkshift").combobox({
                    valueField: 'WORKSHIFTID',
                    textField: 'WORKSHIFTNAME',
                    panelHeight: 200,
                    data: res.DBDataSet.dtWorkShift //下拉数据
                });
                //绑定班下拉框
                $("#selShift").combobox({
                    valueField: 'SHIFTID',
                    textField: 'SHIFTNAME',
                    panelHeight: 200,
                    data: res.DBDataSet.dtShift //下拉数据
                });
                //绑定工厂下拉框
                $("#selFactory").combobox({
                    valueField: 'FACTORYID',
                    textField: 'FACTORYNAME',
                    panelHeight: 200,
                    data: res.DBDataSet.dtFactory, //下拉数据
                    onSelect: function (record) {
                        if (record.FACTORYID !== "") {
                            page.bindWorkCenter(record.FACTORYID); //加载工区
                        }
                    }
                });
            });
        },
        //绑定工区
        bindWorkCenter: function (factoryId) {
            page.post({ action: "GetWorkCenter", factoryId: factoryId }, false, function (res) {
                if (res.Result) {
                    //绑定工区下拉框
                    $("#selWorkCenter").combobox({
                        valueField: 'WORKCENTERID',
                        textField: 'WORKCENTERNAME',
                        panelHeight: 200,
                        data: res.DBTable, //下拉数据
                        onSelect: function (record) {
                            page.bindShift(record.WORKCENTERID);
                        }
                    });
                }
            });
        },
        bindTeam: function (workcenterId) {
            page.post({ action: "GetTeam", workCenterId: workcenterId }, false, function (res) {
                if (res.Result) {
                    //绑定班组
                    $("#Team").combobox({
                        valueField: 'TEAMID',
                        textField: 'TEAMNAME',
                        panelHeight: 200,
                        data: res.DBTable //下拉数据
                    });
                }
            });
        },
        bindShift: function (workcenterId) {
            page.post({ action: "GetShift", workCenterId: workcenterId }, false, function (res) {
                if (res.Result) {
                    //绑定班组
                    $("#selShift").combobox({
                        valueField: 'SHIFTID',
                        textField: 'SHIFTNAME',
                        panelHeight: 200,
                        data: res.DBTable //下拉数据
                    });
                }
            });
        },
        //页面事件绑定
        bind: function () {
            $('#OrderTabel').datagrid({
                singleSelect: true,
                columns: [[
                 { field: 'FACTORYNAME', title: '分厂', width: 150 },
		         { field: 'WORKCENTERNAME', title: '工区（中心）', width: 180 },
                 { field: 'SHIFTNAME', title: '班', width: 120 },
                 { field: 'WORKSHIFTNAME', title: '班次', width: 120 }
                ]],
                onSelect: function (index, row) {
                    //$('#selWorkshift').combobox("setValue", row.WorkshiftID);
                    $('#EditerForm').form('load', row);
                }
            });
        },
        //查询
        searchData: function () {
            clearMessage();
            page.GetShiftWorkshiftMap();
        },
        //查询重置
        searchReset: function () {
            $('#searchForm').form('clear');
            page.bind();
            clearMessage();
        },
        //查询班与班次的绑定信息
        GetShiftWorkshiftMap: function () {
            var frdata = $('#searchForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            var param = {
                action: "GetShiftWorkshiftMap",
                data: JSON.stringify([data])
            };
            page.post(param, true, function (res) {
                $('#OrderTabel').datagrid('loadData', res.DBTable);
            });
        },
        CreateShiftWorkshiftMap: function () {
            $('#EditerForm').form('clear');
        },
        SaveShiftWorkshiftMap: function () {
            var eddata = $('#EditerForm').serializeArray();
            var data = {};
            $.each(eddata, function () {
                data[this.name] = this.value
            });
            if (data.WorkshiftID == "") { displayMessage("请选择班次，再进行保存", false); return; }
            if (data.SHIFTID == "") { displayMessage("请选择班，再进行保存",false); return; }
            var param = {
                action: "SaveShiftWorkshiftMap",
                data: JSON.stringify([data])
            };
            page.post(param, true, function (res) {
                if (res.Result) {
                    page.GetShiftWorkshiftMap();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            clearMessage();
        },

        //post数据
        post: function (param, async, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    }
    $(function () {
        page.init();
    });



</script>
